﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace AUV5.DAL.Handler
{
    public class MessageHandler
    {
        public IList<Model.Message> messagelist = new List<Model.Message>();
        public void GetFullList(object sender, object parameterObj, IList list)
        {
            Model.Message mes = GetFullMessage(sender);
            if (mes != null)
            {
                messagelist.Add(mes);
            }
        }
        public Model.Message GetFullMessage(object sender)
        {
            try
            {
                if (sender != null)
                {

                    Model.Message mes = (Model.Message)sender;
                    Model.UserInfo user = new Model.UserInfo();

                    //Sender
                    user.UserID = mes.Sender;
                    Model.UserInfo sendder = new Model.UserInfo();
                    sendder = Dao.UserInfoSqlMapDao.Instance.GetDetail(user);
                    if (sendder != null)
                    {
                        mes.SenderName = sendder.UserName;
                    }
                    else
                    {
                        mes.SenderName = "找不到发信人";
                    }
                    //Receiver
                    user.UserID = mes.Receiver;
                    Model.UserInfo receiver = Dao.UserInfoSqlMapDao.Instance.GetDetail(user);
                    if (receiver != null)
                    {
                        mes.ReceiverName = receiver.UserName;
                    }
                    else
                    {
                        mes.ReceiverName = "找不到收信人";
                    }

                    //RefService
                    if (!string.IsNullOrEmpty(mes.RefServiceID))
                    {
                        Hashtable ht = new Hashtable();
                        ht.Add("ServiceID", mes.RefServiceID);
                        Model.ServiceInfo refservice = Dao.ServiceInfoSqlMapDao.Instance.GetDetail(ht);
                        mes.RefService = refservice;
                    }


                    //RefRequest
                    if (!string.IsNullOrEmpty(mes.RefRequestID))
                    {
                        Model.RequestInfo refrequest = Dao.RequestInfoSqlMapDao.Instance.GetDetail(mes.RefRequestID);
                        mes.RefRequest = refrequest;
                    }

                    return mes;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error executing MessageHandler,  Cause: " + e.Message, e);
            }

        }
    }
}
